package org.smartercontext.contextmger.utilities;

import java.util.ArrayList;
import java.util.List;

import org.smartercontext.contextmger.contextsphere.ContextManagerController;

import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;

public class GetProfileUtilities {

	private String givenName = "";
	private String gender = "";
	private String birthday = "";
	private String relationshipStatus = "";
	private String significantOther = "";
	private String significantOtherFbId = "";
	private String preferredLanguage = "";
	private List<String>emailAccounts;
	private List<String>mobileNumbers;
	private String prefAddres = "";
	private String prefPlace = "";
	private String prefNeighborhood = "";
	private String prefCity = "";
	private String prefRegion = "";
	private String prefCountry = "";
	private String prefLatitude = "";
	private String prefLongitude = "";
	private String prefZipCode = "";
	
	public GetProfileUtilities(){
		emailAccounts = new ArrayList<>();
		mobileNumbers = new ArrayList<>();
	}
	
	public Model deleteInfoToUserModel(Model usermodel, String type, String data, String username){
		
		String nsUser="http://smartercontext.org/vocabularies/rdf/"+username+".rdf#";
		Resource resource = usermodel.getResource(nsUser+username);
		OntModel modeluser =  ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);;
		modeluser.setNsPrefixes(ContextManagerController.getMappings());
		DatatypeProperty emailAc = modeluser.createDatatypeProperty(ContextManagerController.getNsSchemaPERSONAL()+"emailAccount");
		DatatypeProperty hasMobile = modeluser.createDatatypeProperty(ContextManagerController.getNsSchemaGC()+"hasMobile");
		
		if(type.equals("email")){
			
			StmtIterator iteratorM = resource.listProperties(emailAc);
			Statement stmt = null;
			while(iteratorM.hasNext()){
				Statement temp = iteratorM.next();
				String object = temp.getObject().asLiteral().getString();
				if(object.equals(data)){
					stmt = temp;
				}
			}
			
			if(stmt!=null){
				usermodel.remove(stmt);
			}
			
		}else if(type.equals("mobile")){
			
			StmtIterator iteratorM = resource.listProperties(hasMobile);
			Statement stmt = null;
			Resource mobile = null;
			while(iteratorM.hasNext()){
				Statement temp = iteratorM.next();
				String object = temp.getObject().toString();
				if(object.equals(nsUser+data)){
					stmt = temp;
					mobile = usermodel.getResource(nsUser+data);
				}
			}
			
			
			if(stmt!=null&&mobile!=null){
				usermodel.remove(mobile.listProperties());
				usermodel.remove(stmt);
			}
		}
		
		
		
		return usermodel;
		
	}
	
	public Model setProfileUserModel(Model usermodel, String username){
		
		String nsUser="http://smartercontext.org/vocabularies/rdf/"+username+".rdf#";
		Resource resource = usermodel.getResource(nsUser+username);
		
		if(givenName!=""&&givenName!=null){
		
			Property givenNameP = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"givenName");
			resource.removeAll(givenNameP);
		
			Literal givenNameL = usermodel.createTypedLiteral(new String(givenName));
			resource.addLiteral(givenNameP, givenNameL);
		
		}
		
		if(gender!=""&&gender!=null){
			
			Property genderP = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"hasGender");
			resource.removeAll(genderP);
			
			Literal genderL = usermodel.createLiteral(gender);
			resource.addLiteral(genderP, genderL);
		}
		
		if(birthday!=""&&birthday!=null&&birthday!="//"){
			
			Property birthdayP = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"birthYear");
			resource.removeAll(birthdayP);
			
			Literal bithdayL = usermodel.createTypedLiteral(new String(birthday));
			resource.addLiteral(birthdayP, bithdayL);
			
		}
		
		if(relationshipStatus!=""&&relationshipStatus!=null){
			
			Property relStatusP = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"relationShipStatus");
			resource.removeAll(relStatusP);
			
			Literal relstatusL = usermodel.createLiteral(relationshipStatus);
			resource.addLiteral(relStatusP, relstatusL);
			
			if(relationshipStatus.equals("Divorced")||relationshipStatus.equals("Separated")||relationshipStatus.equals("Single")
					||relationshipStatus.equals("Widowed")){
				Property engagedTo = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"engagedTo");
				
				if(resource.hasProperty(engagedTo)){
				
					Statement stmt=resource.getProperty(engagedTo);
					String urlObject = stmt.getObject().toString();
					
					Resource person = usermodel.getResource(urlObject);
					StmtIterator iteratorPers = person.listProperties();
					List<Statement>listSPers = iteratorPers.toList();
					
					usermodel.remove(listSPers);
					resource.removeAll(engagedTo);
				
				}
			}
			
		}
		
		if(significantOther!=""&&significantOther!=null){
			
			Property engagedTo = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(),"engagedTo");
			
			if(resource.hasProperty(engagedTo)){
			
			Statement stmt=resource.getProperty(engagedTo);
			
			String urlObject = stmt.getObject().toString();
			
			Resource personU = usermodel.getResource(urlObject);
			StmtIterator iteratorP = personU.listProperties();
			List<Statement>persL = iteratorP.toList();
			usermodel.remove(persL);
			resource.removeAll(engagedTo);
			
			Resource person = usermodel.createResource(nsUser+significantOther);
			Property rdfType = usermodel.createProperty(ContextManagerController.getRdf(),"type");
			Property personProp = usermodel.createProperty(ContextManagerController.getNsSchemaGC(),"HumanEntity");
			usermodel.add(person,rdfType,personProp);
			usermodel.add(resource,engagedTo,person);
			
			}else{
				Resource person = usermodel.createResource(nsUser+significantOther);
				Property rdfType = usermodel.createProperty(ContextManagerController.getRdf(),"type");
				Property personProp = usermodel.createProperty(ContextManagerController.getNsSchemaGC(),"HumanEntity");
				usermodel.add(person,rdfType,personProp);
				usermodel.add(resource,engagedTo,person);
			}
		}
		
		OntModel modeluser =  ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);;
		modeluser.setNsPrefixes(ContextManagerController.getMappings());
		
		if(!emailAccounts.isEmpty()){
			
			
			DatatypeProperty emailAc = modeluser.createDatatypeProperty(ContextManagerController.getNsSchemaPERSONAL()+"emailAccount");
			if(resource.hasProperty(emailAc)){
				
				resource.removeAll(emailAc);
				
				for(int i=0;i<emailAccounts.size();i++){
					String emAc = emailAccounts.get(i);
					Literal emailAcL = modeluser.createTypedLiteral(new String(emAc));
					usermodel.addLiteral(resource, emailAc, emailAcL);
				}
				
			}else{
				
				for(int i=0;i<emailAccounts.size();i++){
					String emAc = emailAccounts.get(i);
					Literal emailAcL = modeluser.createTypedLiteral(new String(emAc));
					usermodel.addLiteral(resource, emailAc, emailAcL);
				}
				
			}
		}
		
		OntModel modelMob = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
		modelMob.setNsPrefixes(ContextManagerController.getMappings());
		DatatypeProperty mobileNumber = modelMob.createDatatypeProperty(ContextManagerController.getNsSchemaGC()
				+"mobileNumber");
		
		if(!mobileNumbers.isEmpty()){
			
			DatatypeProperty hasMobile = modeluser.createDatatypeProperty(ContextManagerController.getNsSchemaGC()+"hasMobile");
			if(resource.hasProperty(hasMobile)){
				Statement stmt = resource.getProperty(hasMobile);
				String urlObect = stmt.getObject().toString();
				
				Resource mobile = usermodel.getResource(urlObect);
				StmtIterator iteratorMobile = mobile.listProperties();
				List<Statement>listSM = iteratorMobile.toList();
				usermodel.remove(listSM);
			}
			
			for(int i=0;i<mobileNumbers.size();i++){
				String number = mobileNumbers.get(i);
				Resource mobile = usermodel.createResource(nsUser+"Mobile"+i);
				Property rdfTypeM = usermodel.createProperty(ContextManagerController.getRdf(),"type");
				Property mobilePropM = usermodel.createProperty(ContextManagerController.getNsSchemaGC(),"MobilePhone");
				
				Literal mobileNumberL = modelMob.createTypedLiteral(new String(number)); 
				
				usermodel.add(mobile,rdfTypeM,mobilePropM);
				usermodel.addLiteral(mobile, mobileNumber, mobileNumberL);
				usermodel.add(resource,hasMobile,mobile);				
				
			}
		}
		
		if(prefPlace!=""&&prefPlace!=null){
			
			Property preferredLocation = usermodel.createProperty(ContextManagerController.getNsSchemaPERSONAL(), "preferredLocation");
			Property locatedIn = usermodel.createProperty(ContextManagerController.getNsSchemaGC(),"locatedIn");
			OntModel modelGeo = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
			modelGeo.setNsPrefixes(ContextManagerController.getMappings());
			DatatypeProperty geoLocationClassification = 
					modelGeo.createDatatypeProperty(ContextManagerController.getNsSchemaGC()
							+ "geoLocationClassification");
			
			if(resource.hasProperty(preferredLocation)){
				
				Statement stmt = resource.getProperty(preferredLocation);
				String urlPlace = stmt.getObject().toString();
				
				Resource place = usermodel.getResource(urlPlace);
				usermodel.remove(place.listProperties());
				
//				Statement stmt = resource.getProperty(preferredLocation);
//				String urlPlace = stmt.getObject().toString();
//				
//				Resource place = usermodel.getResource(urlPlace);
//				if(place.hasProperty(locatedIn)){
//					Statement stmtPlace = place.getProperty(locatedIn);
//					String urlNeighborhood = stmtPlace.getObject().toString();
//					
//					Resource neighborhood = usermodel.getResource(urlNeighborhood);
//					if(neighborhood.hasProperty(locatedIn)){
//						Statement stmtNeighborhood = neighborhood.getProperty(locatedIn);
//						String urlCity = stmtNeighborhood.getObject().toString();
//						
//						Resource city = usermodel.getResource(urlCity);
//						if(city.hasProperty(locatedIn)){
//							Statement stmtCity = city.getProperty(locatedIn);
//							String urlRegion = stmtCity.getObject().toString();
//														
//							Resource region = usermodel.getResource(urlRegion);
//							if(region.hasProperty(locatedIn)){
//								Statement stmtRegion = region.getProperty(locatedIn);
//								String urlCountry = stmtRegion.getObject().toString();
//								
//								Resource country = usermodel.getResource(urlCountry);
//								StmtIterator iteratorCountry = country.listProperties();
//								List<Statement>toEraseC = iteratorCountry.toList();
//								usermodel.remove(toEraseC);
//								
//								StmtIterator iteratorRegion = region.listProperties();
//								List<Statement>toEraseR = iteratorRegion.toList();
//								usermodel.remove(toEraseR);
//								
//								StmtIterator iteratorCity = city.listProperties();
//								List<Statement>toEraseCi = iteratorCity.toList();
//								usermodel.remove(toEraseCi);
//								
//								StmtIterator iteratorNeighb = neighborhood.listProperties();
//								List<Statement>toEraseN = iteratorNeighb.toList();
//								usermodel.remove(toEraseN);
//								
//							}else{
//								StmtIterator iteratorRegion = region.listProperties();
//								List<Statement>toEraseR = iteratorRegion.toList();
//								usermodel.remove(toEraseR);
//								
//								StmtIterator iteratorCity = city.listProperties();
//								List<Statement>toEraseCi = iteratorCity.toList();
//								usermodel.remove(toEraseCi);
//								
//								StmtIterator iteratorNeighb = neighborhood.listProperties();
//								List<Statement>toEraseN = iteratorNeighb.toList();
//								usermodel.remove(toEraseN);
//							}
//						}else{
//							StmtIterator iteratorCity = city.listProperties();
//							List<Statement>toEraseCi = iteratorCity.toList();
//							usermodel.remove(toEraseCi);
//							
//							StmtIterator iteratorNeighb = neighborhood.listProperties();
//							List<Statement>toEraseN = iteratorNeighb.toList();
//							usermodel.remove(toEraseN);
//						}
//					}else{
//						StmtIterator iteratorNeighb = neighborhood.listProperties();
//						List<Statement>toEraseN = iteratorNeighb.toList();
//						usermodel.remove(toEraseN);
//					}
//					
//				}
//				
//				StmtIterator iterator = place.listProperties();
//				List<Statement>stmts = iterator.toList();				
//				usermodel.remove(stmts);
				
				resource.removeAll(preferredLocation);
				
			}
			
			if(prefCountry!=""&&prefCountry!=null){
				
				Resource country = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCountry);
				Literal countryL = modelGeo.createTypedLiteral(new String("Country"));
				usermodel.addLiteral(country, geoLocationClassification, countryL);
			}
			
			if(prefRegion!=""&&prefRegion!=null){
				
				Resource region = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefRegion);
				Literal regionL = modelGeo.createTypedLiteral(new String("Region"));
				if(prefCountry!=""&&prefCountry!=null){
					Resource country = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCountry);
					usermodel.add(region,locatedIn,country);
				}
				usermodel.addLiteral(region, geoLocationClassification, regionL);
			}
			
			if(prefCity!=""&&prefCity!=null){
				
				Resource city = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCity);
				Literal cityL = modelGeo.createTypedLiteral(new String("City"));
				if(prefRegion!=""&&prefRegion!=null){
					Resource region = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefRegion);
					usermodel.add(city,locatedIn,region);
				}else if(prefCountry!=""&&prefCountry!=""){
					Resource country = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCountry);
					usermodel.add(city,locatedIn,country);
				}
				usermodel.addLiteral(city, geoLocationClassification, cityL);
			}
			
			if(prefNeighborhood!=""&&prefNeighborhood!=null){
				
				Resource neighb = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefNeighborhood);
				Literal neighbL = modelGeo.createTypedLiteral(new String("Neighborhood"));
				if(prefCity!=null&&prefCity!=null){
					Resource city = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCity);
					usermodel.add(neighb,locatedIn,city);
				}else if(prefRegion!=null && prefRegion!=""){
					Resource region = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefRegion);
					usermodel.add(neighb,locatedIn,region);
				}else if(prefCountry!=""&& prefCountry!=null){
					Resource country = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCountry);
					usermodel.add(neighb,locatedIn,country);
				}
				usermodel.addLiteral(neighb, geoLocationClassification, neighbL);
				
				
			}
			
			if(prefPlace!=""&&prefPlace!=null){
				
				Resource place = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefPlace);
				Literal placeL = modelGeo.createTypedLiteral(new String("Place"));
				if(prefNeighborhood!=""&&prefNeighborhood!=null){
					Resource neigb = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefNeighborhood);
					usermodel.add(place,locatedIn,neigb);
				}else if(prefCity!=null&&prefCity!=null){
					Resource city = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCity);
					usermodel.add(place,locatedIn,city);
				}else if(prefRegion!=null && prefRegion!=""){
					Resource region = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefRegion);
					usermodel.add(place,locatedIn,region);
				}else if(prefCountry!=""&& prefCountry!=null){
					Resource country = modelGeo.createResource(ContextManagerController.getNsCitiesModel()+prefCountry);
					usermodel.add(place,locatedIn,country);
				}
				
				usermodel.addLiteral(place, geoLocationClassification, placeL);
				
				if(prefAddres!=""&& prefAddres!=null){
					DatatypeProperty address = modelGeo.createDatatypeProperty(new String(ContextManagerController.getNsSchemaGC())+"address");
					Literal addr = modelGeo.createTypedLiteral(new String(prefAddres));
					usermodel.addLiteral(place, address, addr);
				}
				
				if(prefLatitude!=""&&prefLatitude!=null&&prefLongitude!=""&&prefLongitude!=null){
					DatatypeProperty latitude = modelGeo.createDatatypeProperty(new String(ContextManagerController.getNsSchemaGC())+"latitude");
					DatatypeProperty longitude = modelGeo.createDatatypeProperty(new String(ContextManagerController.getNsSchemaGC())+"longitude");
					
					Literal lat = modelGeo.createTypedLiteral(new String(prefLatitude));
					Literal longit = modelGeo.createTypedLiteral(new String(prefLongitude));
					
					usermodel.addLiteral(place, latitude, lat);
					usermodel.addLiteral(place, longitude, longit);
				}
				
				if(prefZipCode!=""&&prefZipCode!=null){
					
					DatatypeProperty zipcode = modelGeo.createDatatypeProperty(new String(ContextManagerController.getNsSchemaGC())+"zipCode");
					Literal zipCL = modelGeo.createTypedLiteral(new String(prefZipCode));
					usermodel.addLiteral(place, zipcode, zipCL);
				}
				
				
			}
			
			if(prefPlace!=""&&prefPlace!=null){
				Resource place = usermodel.getResource(ContextManagerController.getNsCitiesModel()+prefPlace);
				usermodel.add(resource,preferredLocation,place);
			}else if(prefNeighborhood!=""&&prefNeighborhood!=null){
				
				Resource place = usermodel.getResource(ContextManagerController.getNsCitiesModel()+prefNeighborhood);
				usermodel.add(resource,preferredLocation,place);
			}else if(prefCity!=""&&prefCity!=null){
				
				Resource place = usermodel.getResource(ContextManagerController.getNsCitiesModel()+prefCity);
				usermodel.add(resource,preferredLocation,place);
			}else if(prefRegion!=""&&prefRegion!=null){
				
				Resource place = usermodel.getResource(ContextManagerController.getNsCitiesModel()+prefRegion);
				usermodel.add(resource,preferredLocation,place);
			}else if(prefCountry!=""&&prefCountry!=null){
				
				Resource place = usermodel.getResource(ContextManagerController.getNsCitiesModel()+prefCountry);
				usermodel.add(resource,preferredLocation,place);
			}
			
			
		}
		
		return usermodel;
	}
	

	public void getProfileData(Model userModel, String username){
		
		String nsUser="http://smartercontext.org/vocabularies/rdf/"+username+".rdf#";
		
		Resource resource = userModel.getResource(nsUser+username);
		
		StmtIterator iterator=resource.listProperties();
		
		while(iterator.hasNext()){
			Statement stmt = iterator.next();
			String urlPredicate = stmt.getPredicate().toString();
			
			if(urlPredicate.contains("givenName")){
				
				Literal litName = stmt.getObject().asLiteral();
				givenName = litName.getString();
				
			}else if(urlPredicate.contains("hasGender")){
				
				gender=stmt.getObject().toString();
				
			}else if(urlPredicate.contains("birthYear")){
				
				Literal lBirth = stmt.getObject().asLiteral();
				birthday = lBirth.getString();
				
			}else if(urlPredicate.contains("relationShipStatus")){
				
				relationshipStatus = stmt.getObject().toString();
				
			}else if(urlPredicate.contains("preferredLanguage")){
				
				Literal lPrefLang = stmt.getObject().asLiteral();
				preferredLanguage = lPrefLang.getString();
				
			}else if(urlPredicate.contains("hasMobile")){
				
				//Need another iterator
				String mobileUrl=stmt.getObject().toString();
				Resource mobileRes = userModel.getResource(mobileUrl);
				
				StmtIterator iterator2 = mobileRes.listProperties();
				
				while(iterator2.hasNext()){
					Statement stmt2 = iterator2.next();
					String predicate = stmt2.getPredicate().toString();
					
					if(predicate.contains("mobileNumber")){
						Literal litmobile = stmt2.getObject().asLiteral();
						mobileNumbers.add(mobileUrl.split("#")[1]+"#"+litmobile.getString());
					}
				}
				
			}else if(urlPredicate.contains("emailAccount")){
				
				emailAccounts.add(stmt.getObject().asLiteral().getString());
				
			}else if(urlPredicate.contains("preferredLocation")){
				
				//Need another iterator
				String prefLocuUrl=stmt.getObject().toString();
				Resource prefLocRes = userModel.getResource(prefLocuUrl);
				
				StmtIterator iterator2 = prefLocRes.listProperties();
				
				while(iterator2.hasNext()){
					Statement stmt2 = iterator2.next();
					String predicate2 = stmt2.getPredicate().toString();
					
					//First of five
					if(predicate2.contains("geoLocationClassification")){
						
						Literal glc = stmt2.getObject().asLiteral();
						if(glc.getString().equals("Place")){
							prefPlace = stmt2.getSubject().toString().split("#")[1];
						}else if(glc.getString().equals("Neighborhood")){
							prefNeighborhood = stmt2.getSubject().toString().split("#")[1];
						}else if(glc.getString().equals("City")){
							prefCity = stmt2.getSubject().toString().split("#")[1];
						}else if(glc.getString().equals("Country")){
							prefCountry = stmt2.getSubject().toString().split("#")[1];
						}else if(glc.getString().equals("Region")){
							
						}
						
					}else if(predicate2.contains("address")){
						
						Literal add = stmt2.getObject().asLiteral();
						prefAddres = add.getString();
						
					}else if(predicate2.contains("latitude")){
						
						Literal lat = stmt2.getObject().asLiteral();
						prefLatitude = lat.getString();
						
					}else if(predicate2.contains("longitude")){
						
						Literal longit = stmt2.getObject().asLiteral();
						prefLongitude = longit.getString();
						
					}else if(predicate2.contains("zipCode")){
						
						Literal zCode = stmt2.getObject().asLiteral();
						prefZipCode = zCode.getString();
						
					}else if(predicate2.contains("locatedIn")){
						
						//Need another iterator
						String locatedIn1 = stmt2.getObject().toString();
						Resource resource3 = userModel.getResource(locatedIn1);
						
						StmtIterator iterator3 = resource3.listProperties();
						
						while(iterator3.hasNext()){
							Statement stmt3 = iterator3.next();
							String predicate3 = stmt3.getPredicate().toString();
							
							//second of five
							if(predicate3.contains("geoLocationClassification")){
								
								Literal clasif1=stmt3.getObject().asLiteral();
								String clasifS1 = clasif1.getString();
								
								if(clasifS1.equals("Place")){
									prefPlace = stmt3.getSubject().toString().split("#")[1];
								}else if(clasifS1.equals("Neighborhood")){
									prefNeighborhood = stmt3.getSubject().toString().split("#")[1];
								}else if(clasifS1.equals("City")){
									prefCity = stmt3.getSubject().toString().split("#")[1];
								}else if(clasifS1.equals("Region")){
									prefRegion = stmt3.getSubject().toString().split("#")[1];
								}else if(clasifS1.equals("Country")){
									prefCountry = stmt3.getSubject().toString().split("#")[1];
								}
							}else if(predicate3.contains("locatedIn")){
								
								String locatedIn2 = stmt3.getObject().toString();
								Resource resource4 = userModel.getResource(locatedIn2);
								
								StmtIterator iterator4 = resource4.listProperties();
								
								while(iterator4.hasNext()){
									Statement stmt4 = iterator4.next();
									String predicate4 = stmt4.getPredicate().toString();
									
									//third of five
									if(predicate4.contains("geoLocationClassification")){
										
										Literal clasif2 = stmt4.getObject().asLiteral();
										String clasifS2 = clasif2.getString();
										
										if(clasifS2.equals("Place")){
											prefPlace = stmt4.getSubject().toString().split("#")[1];
										}else if(clasifS2.equals("Neighborhood")){
											prefNeighborhood = stmt3.getSubject().toString().split("#")[1];
										}else if(clasifS2.equals("City")){
											prefCity = stmt4.getSubject().toString().split("#")[1];
										}else if(clasifS2.equals("Region")){
											prefRegion = stmt4.getSubject().toString().split("#")[1];
										}else if(clasifS2.equals("Country")){
											prefCountry = stmt4.getSubject().toString().split("#")[1];
										}
									}else if(predicate4.contains("locatedIn")){
										
										String locatedIn3=stmt4.getObject().toString();
										Resource resource5 = userModel.getResource(locatedIn3);
										
										StmtIterator iterator5 = resource5.listProperties();
										
										while(iterator5.hasNext()){
											Statement stmt5 = iterator5.next();
											String predicate5 = stmt5.getPredicate().toString();
											
											//fourth of five
											if(predicate5.contains("geoLocationClassification")){
												
												Literal clasif3 = stmt5.getObject().asLiteral();
												String clasifS3 = clasif3.getString();
												
												if(clasifS3.equals("Place")){
													prefPlace = stmt5.getSubject().toString().split("#")[1];
												}else if(clasifS3.equals("Neighborhood")){
													prefNeighborhood = stmt5.getSubject().toString().split("#")[1];
												}else if(clasifS3.equals("City")){
													prefCity = stmt5.getSubject().toString().split("#")[1];
												}else if(clasifS3.equals("Region")){
													prefRegion = stmt5.getSubject().toString().split("#")[1];
												}else if(clasifS3.equals("Country")){
													prefCountry = stmt5.getSubject().toString().split("#")[1];
												}
											}else if(predicate5.contains("locatedIn")){
												
												String locatedIn4 = stmt5.getObject().toString();
												Resource resource6 = userModel.getResource(locatedIn4);
												
												StmtIterator iterator6 = resource6.listProperties();
												while(iterator6.hasNext()){
													Statement stmt6 = iterator6.next();
													String predicate6 = stmt6.getPredicate().toString();
													
													//fifth of five
													if(predicate6.contains("geoLocationClassification")){
														Literal clasif4 = stmt6.getObject().asLiteral();
														String clasifS4 = clasif4.getString();
														
														if(clasifS4.equals("Place")){
															prefPlace = stmt6.getSubject().toString().split("#")[1];
														}else if(clasifS4.equals("Neighborhood")){
															prefNeighborhood = stmt6.getSubject().toString().split("#")[1];
														}else if(clasifS4.equals("City")){
															prefCity = stmt6.getSubject().toString().split("#")[1];
														}else if(clasifS4.equals("Region")){
															prefRegion = stmt6.getSubject().toString().split("#")[1];
														}else if(clasifS4.equals("Country")){
															prefCountry = stmt6.getSubject().toString().split("#")[1];
														}
													}
												}
											}
										}
										
									}
								}
							}
						}
					}
					
				}
				
				
			}else if(urlPredicate.contains("engagedTo")){
				
				//Need another iterator
				String signifOth = stmt.getObject().toString();
				
				String[]split = signifOth.split("#");
				significantOther = split[1];
				
				Resource signifOthRes = userModel.getResource(signifOth);
				
				StmtIterator iterator2 = signifOthRes.listProperties();
				while(iterator2.hasNext()){
					Statement stmt2 = iterator2.next();
					
					if(stmt2.getPredicate().toString().contains("facebookId")){
						
						Literal lt = stmt2.getLiteral();
						significantOtherFbId = lt.getString();
					}
				}
			}
		}
		
	
		
	}
	
	public String getGivenName() {
		return givenName;
	}


	public void setGivenName(String givenName) {
		this.givenName = givenName;
	}


	public String getGender() {
		return gender;
	}


	public void setGender(String gender) {
		this.gender = gender;
	}


	public String getBirthday() {
		return birthday;
	}


	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}


	public String getRelationshipStatus() {
		return relationshipStatus;
	}


	public void setRelationshipStatus(String relationshipStatus) {
		this.relationshipStatus = relationshipStatus;
	}


	public String getSignificantOther() {
		return significantOther;
	}


	public void setSignificantOther(String significantOther) {
		this.significantOther = significantOther;
	}


	public String getPreferredLanguage() {
		return preferredLanguage;
	}


	public void setPreferredLanguage(String preferredLanguage) {
		this.preferredLanguage = preferredLanguage;
	}


	public List<String> getEmailAccounts() {
		return emailAccounts;
	}


	public void setEmailAccounts(List<String> emailAccounts) {
		this.emailAccounts = emailAccounts;
	}


	public List<String> getMobileNumbers() {
		return mobileNumbers;
	}


	public void setMobileNumbers(List<String> mobileNumbers) {
		this.mobileNumbers = mobileNumbers;
	}


	public String getPrefAddres() {
		return prefAddres;
	}


	public void setPrefAddres(String prefAddres) {
		this.prefAddres = prefAddres;
	}


	public String getPrefNeighborhood() {
		return prefNeighborhood;
	}


	public void setPrefNeighborhood(String prefNeighborhood) {
		this.prefNeighborhood = prefNeighborhood;
	}


	public String getPrefCity() {
		return prefCity;
	}


	public void setPrefCity(String prefCity) {
		this.prefCity = prefCity;
	}


	public String getPrefCountry() {
		return prefCountry;
	}


	public void setPrefCountry(String prefCountry) {
		this.prefCountry = prefCountry;
	}

	public String getSignificantOtherFbId() {
		return significantOtherFbId;
	}

	public void setSignificantOtherFbId(String significantOtherFbId) {
		this.significantOtherFbId = significantOtherFbId;
	}

	public String getPrefLatitude() {
		return prefLatitude;
	}

	public void setPrefLatitude(String prefLatitude) {
		this.prefLatitude = prefLatitude;
	}

	public String getPrefLongitude() {
		return prefLongitude;
	}

	public void setPrefLongitude(String prefLongitude) {
		this.prefLongitude = prefLongitude;
	}

	public String getPrefZipCode() {
		return prefZipCode;
	}

	public void setPrefZipCode(String prefZipCode) {
		this.prefZipCode = prefZipCode;
	}

	public String getPrefPlace() {
		return prefPlace;
	}

	public void setPrefPlace(String prefPlace) {
		this.prefPlace = prefPlace;
	}

	public String getPrefRegion() {
		return prefRegion;
	}

	public void setPrefRegion(String prefRegion) {
		this.prefRegion = prefRegion;
	}
	
	
	
}
